<style lang="scss" scoped>
    .editPassword{
        height: 100vh;
        background-color: #f5f5f5;
    }
    .content{
        height: 90px;
        background-color: #fff;
    }
    .btn{
        margin-top: 20px;
    }
</style>
<template>
    <div class="editPassword">
        <p-navigator 
            :text="'修改密码'"
        />
        <div class="content">
            <van-cell-group>
                <van-field 
                    type="password"
                    v-model="obj.loginPassword" 
                    label="密码" 
                    placeholder="请输入密码" />
            </van-cell-group>
            <van-cell-group>
                <van-field 
                    type="password"
                    v-model="obj.loginRePassword" 
                    label="确认密码" 
                    placeholder="请输入确认密码" />
            </van-cell-group>
        </div>
        <div class="btn">
            <van-row>
                <van-col span="18" offset="3">
                    <van-button @click="submit()" round block type="info">修改密码</van-button>
                </van-col>
            </van-row>
        </div>
    </div>
</template>
<script>
// 接口
import { forgetPassword } from '@/api'
export default {
    methods: {
        submit(){
            // 验证密码
            if(this.obj.loginPassword.length < 6){
                this.$toast('密码长度不能小于6位');
                return
            }
            // 两次密码输入不一致
            if(this.obj.loginPassword != this.obj.loginRePassword){
                this.$toast('两次密码输入不一致');
                return
            }
            // 调用修改密码接口
            forgetPassword(this.obj).then(res => {
                // console.log(res.data);
                if(res.data.code == 1){
                    // 提示
                    this.$toast('密码修改成功');
                    // 延迟跳转
                    setTimeout(() => {
                        this.$router.push('/login')
                    }, 1500);
                }
            })
        }
    },
    data() {
        return {
            obj: {
                loginPassword: '',
                loginRePassword: ''
            }
        }
    }
}
</script>